package com.lecture.essence.demo02;

import cn.hutool.core.util.ArrayUtil;
import com.lecture.essence.demo02.IFXNewsListener;
import com.lecture.essence.demo02.IFXNewsPersister;

public class FXNewsProvider {

    private IFXNewsListener newsListener;

    private IFXNewsPersister newsPersister;

    public FXNewsProvider(IFXNewsListener newsListener,IFXNewsPersister newsPersister) {
        this.newsListener = newsListener;
        this.newsPersister = newsPersister;
    }

    public void getAndPersistNews() {
        String[] newsIds = newsListener.getAvailableNewsIds();
        if (ArrayUtil.isEmpty(newsIds)) {
            return;
        }
        for (String newsId : newsIds) {
            System.out.println("newsId：" + newsId);
            FXNewsBean newsBean = newsListener.getNewsByPK(newsId);
            newsPersister.persistNews(newsBean);
            newsListener.postProcessIfNecessary(newsId);
        }
    }

}
